home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir39 / borfix.zip / TI705.C < prev   
C/C++ Source or Header  |  1994-08-23  |  2KB  |  58 lines

  1.   /************************************************************************
  2.  
  3.   This program demonstrates the dynamic allocation of a memory
  4.   block larger than 64K bytes using farcalloc().  It should not be
  5.   compiled in the Tiny memory model.  The program calls farcoreleft
  6.   prior to allocating the block of memory to determine how much
  7.   memory is available.  Note that this method will not be accurate
  8.   if memory has been previously allocated and then released as the
  9.   released memory is handled differently. If you choose to run this
  10.   program from inside the integrated development environment you
  11.   must set the head size under OPTIONS/DEBUGGER to at least the
  12.   size of the two parameters passed to farcalloc() + 5 bytes. Also
  13.   note that farcalloc can be interchanged freely with farmalloc or
  14.   farrealloc in this example.
  15.  
  16.   ***********************************************************************/
  17.  
  18.  
  19.   #include <stdio.h>
  20.   #include <alloc.h>
  21.   #include <string.h>
  22.   #include <dos.h>
  23.   #include <conio.h>
  24.  
  25.   int main(void)
  26.   {
  27.      int huge *fptr;
  28.      unsigned long val;
  29.  
  30.      clrscr();
  31.  
  32.      /* Check the amount of memory available if no blocks have been
  33.         freed */
  34.      printf("\nMemory available on the far heap:   %lu\n",val =
  35.              farcoreleft());
  36.  
  37.      /* allocate memory for the far pointer */
  38.      fptr = (int huge *) farcalloc( 66000L, sizeof(int));
  39.  
  40.  
  41.      /* display string (note the F modifier) */
  42.      printf("Address of allocated block is:      %Fp", fptr);
  43.  
  44.  
  45.      /* Check how much memory is left */
  46.      printf("\nMemory left on the far heap:        %lu\n",val =
  47.                farcoreleft());
  48.  
  49.      getch();
  50.  
  51.      /* free the memory */
  52.      farfree((int far *) fptr);
  53.  
  54.      return 0;
  55.   }
  56.  
  57.  
  58.